﻿using Mind.Data;


namespace Mind.SampleProject.Data
{

    public class ProductSchema : Schema<ProductSchema>
    {
        private const string _TableName = "Product";
        public const string ProductIdColumn = "ProductId";
        public const string ProductTypeIdColumn = "ProductTypeId";
        public const string NameColumn = "Name";

        protected override void GenerateColumns()
        {
            AddColumnInfo(ColumnInfo.CreatePrimaryKeyColumn(ProductIdColumn, typeof(int)));
            AddColumnInfo(ColumnInfo.CreateNormalColumn(ProductTypeIdColumn, typeof(int), false , 1));
            AddColumnInfo(ColumnInfo.CreateNormalColumn(NameColumn, typeof(string), false, 0));
            
        }

        protected override void GenerateLockups()
        {
            AddLockupInfo(ProductTypeIdColumn, ProductType.Schema, LockupType.Joinned, typeof(ProductType));
        }

        protected override string GetTableName()
        {
            return _TableName;
        }
    }


    public partial class Product : Wrapper<Product, ProductSchema>
    {


        public int ProductId
        {
            get
            {
                return GetColumnValue<int>(ProductSchema.ProductIdColumn).GetValueOrDefault();
            }

            set
            {
                SetColumnValue(ProductSchema.ProductIdColumn, value);
            }
        }

        public string Name
        {
            get
            {
                return GetColumnString(SellerSchema.NameColumn);
            }

            set
            {
                SetColumnValue(SellerSchema.NameColumn, value);
            }
        }

        public int ProductTypeId
        {
            get
            {
                return GetColumnValue<int>(ProductSchema.ProductTypeIdColumn).GetValueOrDefault();
            }

            set
            {
                SetColumnValue(ProductSchema.ProductTypeIdColumn, value);
            }
        }

        public ProductType ProductType
        {
            get
            {
                return GetLockupValue<ProductType>(ProductSchema.ProductTypeIdColumn);
            }
            set
            {
                SetLockupValue(ProductSchema.ProductIdColumn, value);
            }
        }

       
    }


    
    
}
